package com.easyattendance.model;

import java.beans.ConstructorProperties;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;






import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

@Entity
@Table(name="TBL_TEACHER")
public class Teacher {
	
	@Id
	@GenericGenerator(name="user_id",strategy="foreign")
	@Column(name="teacher_id",nullable=false,length=15)
	private String teacher_id;
	
	/*@GenericGenerator(name="section_id",strategy="foreign")
	@Column(name="section_id")
	private String section_id; */
	
/*	 one to one mapping of Teacher */
	@OneToOne(optional=false)
	@PrimaryKeyJoinColumn
	private User user;
	
	@ManyToOne
	@JoinColumn(name="section_id",nullable=false)
	private Section section;
	
	/* One to Many mappings of Teacher */
	
	/*@OneToMany(mappedBy="teacher")
	private Set<AttendanceTakenBy> attendances; */
	
	@OneToMany(mappedBy="teacher",fetch=FetchType.LAZY)
	@Cascade(value={org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private Set<SubjectTeacher> subjectTeachers;  
	
	@OneToMany(mappedBy="teacher")
	@Cascade(value={org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private Set<Assignment> assignments;
	
	@OneToMany(mappedBy="teacher")
	@Cascade(value={org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private Set<TimeTable> timeTables; 
	
	@OneToMany(mappedBy="teacher")
	@Cascade(value={org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private Set<MaterialClass> materialClass;
	
	@OneToMany(mappedBy="proxyTeacher")
	@Cascade(value={org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private Set<Proxy> proxyTeachers;
	
	@OneToMany(mappedBy="subjectTeacher")
	@Cascade(value={org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private Set<Proxy> subjectTeacher;
	
	@OneToMany(mappedBy="teacher")
	@Cascade(value={org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private Set<AttendanceTakenBy> attendanceTakenByTeacher;
	
	@Column(name="teacher_name",length=32,nullable=false)
	private String teacher_name;
	
	@Column(name="teacher_lname",length=32,nullable=false)
	private String teacher_lname;
	
	@GenericGenerator(name="email_id",strategy="foreign")
	//@Column(name="teacher_email_id")
	@JoinColumn(name="email_id", insertable=false, updatable=false, referencedColumnName="email_id")
	private String email_id;
	
	@Column(name="teacher_address",length=100)
	private String teacher_address;
	
	@Column(name="teacher_mobile_no",length=10)
	private long teacher_mobile_no;
	
	@Column(name="teacher_resi_no",length=10)
	private long teacher_resi_no;
	
	@Column(name="isClassTeacher", columnDefinition="boolean")
	private boolean isClassTeacher; 
	
	@Column(name="teacher_skills",length=50)
	private String teacher_skills;
	
	@Column(name="teacher_gender",length=10)
	private String teacher_gender;
	
	@Column(name="teacher_dob")
	private Date teacher_dob;
	
	@Column(name="teacher_doj")
	private Date teacher_doj;

	public Teacher() {
		super();
	}

	

	public Teacher(String teacher_id, User user, Section section,
			Set<SubjectTeacher> subjectTeachers, Set<Assignment> assignments,
			Set<TimeTable> timeTables, Set<MaterialClass> materialClass,
			String teacher_name, String teacher_lname, String email_id,
			String teacher_address, long teacher_mobile_no,
			long teacher_resi_no, boolean isClassTeacher, String teacher_skills, String gender, Date dob, Date doj) {
		super();
		this.teacher_id = teacher_id;
		this.user = user;
		this.section = section;
		this.subjectTeachers = subjectTeachers;
		this.assignments = assignments;
		this.timeTables = timeTables;
		this.materialClass = materialClass;
		this.teacher_name = teacher_name;
		this.teacher_lname = teacher_lname;
		this.email_id = email_id;
		this.teacher_address = teacher_address;
		this.teacher_mobile_no = teacher_mobile_no;
		this.teacher_resi_no = teacher_resi_no;
		this.isClassTeacher = isClassTeacher;
		this.teacher_skills = teacher_skills;
		this.teacher_gender = gender;
		this.teacher_dob = dob;
		this.teacher_doj = doj;
	}



	public Teacher(String teacher_id, String teacher_name, String teacher_lname,
			String teacher_email_id, String teacher_address,
			long teacher_mobile_no, long teacher_resi_no, boolean isClassTeacher, String teacher_skills, String gender, Date dob, Date doj) {
		super();
		this.teacher_id = teacher_id;
		this.teacher_name = teacher_name;
		this.teacher_lname = teacher_lname;
		this.email_id = teacher_email_id;
		this.teacher_address = teacher_address;
		this.teacher_mobile_no = teacher_mobile_no;
		this.teacher_resi_no = teacher_resi_no;
		this.isClassTeacher = isClassTeacher;
		this.teacher_skills=teacher_skills;
		this.teacher_gender = gender;
		this.teacher_dob = dob;
		this.teacher_doj = doj;
	}
	
	public Teacher(String teacher_name, String teacher_lname, String teacher_email_id,
			String teacher_address) {
		super();
		this.teacher_name = teacher_name;
		this.teacher_lname = teacher_lname;
		this.email_id = teacher_email_id;
		this.teacher_address = teacher_address;
	}
	
	public String getTeacher_id() {
		return teacher_id;
	}

	public void setTeacher_id(String teacher_id) {
		this.teacher_id = teacher_id;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Section getSection() {
		return section;
	}

	public void setSection(Section section) {
		this.section = section;
	}
	
	

	/*public Set<Subject> getSubjects() {
		return subjects;
	}

	public void setSubjects(Set<Subject> subjects) {
		this.subjects = subjects;
	}*/

	/*public String getSection_id() {
		return section_id;
	}

	public void setSection_id(String section_id) {
		this.section_id = section_id;
	} */

	/*public boolean isClassTeacher() {
		return isClassTeacher;
	}

	public void setClassTeacher(boolean isClassTeacher) {
		this.isClassTeacher = isClassTeacher;
	} */

	public String getTeacher_skills() {
		return teacher_skills;
	}

	public void setTeacher_skills(String teacher_skills) {
		this.teacher_skills = teacher_skills;
	}

	public Set<Assignment> getAssignments() {
		return assignments;
	}

	public void setAssignments(Set<Assignment> assignments) {
		this.assignments = assignments;
	}

	/* public Class getClasses() {
		return classes;
	}

	public void setClasses(Class classes) {
		this.classes = classes;
	}  */

	public Set<SubjectTeacher> getSubjectTeachers() {
		return subjectTeachers;
	}

	public Set<MaterialClass> getMaterialClass() {
		return materialClass;
	}

	public void setMaterialClass(Set<MaterialClass> materialClass) {
		this.materialClass = materialClass;
	}



	public void setSubjectTeachers(Set<SubjectTeacher> subjectTeachers) {
		this.subjectTeachers = subjectTeachers;
	}
	
	

	public Set<TimeTable> getTimeTables() {
		return timeTables;
	}



	public void setTimeTables(Set<TimeTable> timeTables) {
		this.timeTables = timeTables;
	}



	public String getTeacher_name() {
		return teacher_name;
	}

	public String getTeacher_lname() {
		return teacher_lname;
	}

	public void setTeacher_lname(String teacher_lname) {
		this.teacher_lname = teacher_lname;
	}

	public void setTeacher_name(String teacher_name) {
		this.teacher_name = teacher_name;
	}

	public String getTeacher_email_id() {
		return email_id;
	}

	public void setTeacher_email_id(String teacher_email_id) {
		this.email_id = teacher_email_id;
	}

	public String getTeacher_address() {
		return teacher_address;
	}

	public void setTeacher_address(String teacher_address) {
		this.teacher_address = teacher_address;
	}

	public long getTeacher_mobile_no() {
		return teacher_mobile_no;
	}

	public void setTeacher_mobile_no(long teacher_mobile_no) {
		this.teacher_mobile_no = teacher_mobile_no;
	}

	public long getTeacher_resi_no() {
		return teacher_resi_no;
	}

	public void setTeacher_resi_no(long teacher_resi_no) {
		this.teacher_resi_no = teacher_resi_no;
	}
	
	
	
	public boolean isClassTeacher() {
		return isClassTeacher;
	}

	public void setClassTeacher(boolean isClassTeacher) {
		this.isClassTeacher = isClassTeacher;
	}

	public Teacher(String teacher_id) {
		super();
		this.teacher_id = teacher_id;
	}

	public String getTeacher_gender() {
		return teacher_gender;
	}

	public void setTeacher_gender(String teacher_gender) {
		this.teacher_gender = teacher_gender;
	}

	public Date getTeacher_dob() {
		return teacher_dob;
	}

	public void setTeacher_dob(Date teacher_dob) {
		this.teacher_dob = teacher_dob;
	}

	public Date getTeacher_doj() {
		return teacher_doj;
	}

	public void setTeacher_doj(Date teacher_doj) {
		this.teacher_doj = teacher_doj;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((teacher_address == null) ? 0 : teacher_address.hashCode());
		result = prime
				* result
				+ ((email_id == null) ? 0 : email_id.hashCode());
		
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		Teacher other = (Teacher) obj;
		
		if (teacher_address.equals(other.teacher_address)) {
			if (email_id.equals(other.email_id)) {
				return true;
			}
		}
		
		return false;
	}

	
}
